<?php
/* $websiteId 			= Mage::helper("qslb")->_getwebsiteId();
if($websiteId == '11'){
	require_once(Mage::getBaseDir('lib')."/K3/k3.class.php");
	$cookie_jar 	= tempnam('./tmp','CloudSession');
	$webpost 		= new Webpost();
	$result 		= $webpost->invoke_login($cookie_jar);
	$result 		= json_decode($result,true);
	header("Content-type: text/html; charset=utf-8");
	if($result['LoginResultType'] == 1 || $result['LoginResultType'] == -5){
		//其它入库用途
		$FQTRK_TYPE_data = array(
				'0'=>array(
						"FormId"       => 'BOS_ASSISTANTDATA_DETAIL',
						"TopRowCount"  => 0,
						"FilterString" => "Fid.Fnumber = 'QTRKYT'" ,
						"OrderString"  => "" ,
						"FieldKeys"    => "FNumber,FDataValue" ,
				)
		);
		$post_FQTRK_TYPE 			   = $webpost->create_postdata($FQTRK_TYPE_data);
		$FQTRK_TYPE_all 			   = $webpost->invoke_searchlist($post_FQTRK_TYPE,$cookie_jar);
		$FQTRK_TYPE_all 			   = json_decode($FQTRK_TYPE_all);
		$result['FQTRK_TYPE_in'] 	   = $FQTRK_TYPE_all->Result->Result;
		//其它出库用途
		$FQTRK_TYPE_data = array(
				'0'=>array(
						"FormId"       => 'BOS_ASSISTANTDATA_DETAIL',
						"TopRowCount"  => 0,
						"FilterString" => "Fid.Fnumber = 'QTCKYT'" ,
						"OrderString"  => "" ,
						"FieldKeys"    => "FNumber,FDataValue" ,
				)
		);
		$post_FQTRK_TYPE 			   = $webpost->create_postdata($FQTRK_TYPE_data);
		$FQTRK_TYPE_all 			   = $webpost->invoke_searchlist($post_FQTRK_TYPE,$cookie_jar);
		$FQTRK_TYPE_all 			   = json_decode($FQTRK_TYPE_all);
		$result['FQTRK_TYPE_out'] 	   = $FQTRK_TYPE_all->Result->Result;
		//供应商
		$FSUPPLIERID_data = array(
				'0'=>array(
						"FormId"       => 'BD_Supplier',
						"TopRowCount"  => 0,
						"FilterString" => 'FUSEORGID.Fnumber='.$websiteId.'' ,
						"OrderString"  => "" ,
						"FieldKeys"    => "FNumber,FName" ,
				)
		);
		$post_FSUPPLIERID 			   = $webpost->create_postdata($FSUPPLIERID_data);
		$FSUPPLIERID_all 			   = $webpost->invoke_searchlist($post_FSUPPLIERID,$cookie_jar);
		$FSUPPLIERID_all 	           = json_decode($FSUPPLIERID_all);
		$result['FSUPPLIERID'] 		   = $FSUPPLIERID_all->Result->Result;
		//验收员FACCEPTANCE
		$FACCEPTANCE_data = array(
				'0'=>array(
						"FormId"       => 'BD_Empinfo',
						"TopRowCount"  => 0,
						"FilterString" => 'FUSEORGID.Fnumber='.$websiteId.'' ,
						"OrderString"  => "" ,
						"FieldKeys"    => "FNumber,FName" ,
				)
		);
		$post_FACCEPTANCE 			   = $webpost->create_postdata($FACCEPTANCE_data);
		$FACCEPTANCE_all 			   = $webpost->invoke_searchlist($post_FACCEPTANCE,$cookie_jar);
		$FACCEPTANCE_all 			   = json_decode($FACCEPTANCE_all);
		$result['FACCEPTANCE'] 		   = $FACCEPTANCE_all->Result->Result;
		//部门
		$FDEPTID_data1 = array(
				'0'=>array(
						"FormId"       => 'BD_Department',
						"TopRowCount"  => 0,
						"FilterString" => 'FUSEORGID.Fnumber='.$websiteId.'' ,
						"OrderString"  => "" ,
						"FieldKeys"    => "FNumber,FName" ,
				)
		);
		$post_FDEPTID 				   = $webpost->create_postdata($FDEPTID_data1);
		$FDEPTID_all 				   = $webpost->invoke_searchlist($post_FDEPTID,$cookie_jar);
		$FDEPTID_all 				   = json_decode($FDEPTID_all);
		$result['FDEPTID'] 			   = $FDEPTID_all->Result->Result;
	}
	$k3_info = $result;
}
 */
?>

<div class="entry-edit">
    <div class="entry-edit-head">
    <h4 class="icon-head head-edit-form fieldset-legend">客户退货记录</h4>
    <div class="form-buttons"></div>
</div>
    <div class="fieldset  ignore-validate" id="coupons_information_fieldset">
    <div class="hor-scroll">
    <table cellspacing="0" class="form-list">
        <tbody>
            <tr>
        		<td colspan="2" class="hidden">
        			<input id="product_id" name="product_id" value="<?php echo $this->getProduct()->getId();?>" type="hidden" class=""/>
        			<input id="store_id" name="store" value="<?php echo $this->getRequest()->getParam('store');?>" type="hidden" class="">
        		</td>
    		</tr>
			<tr>
        		<td class="label"><label for="operation">操作<span class="required">*</span></label></td>
    			<td class="value">
	        		<select id="operation" name="operation" class="required-entry select">
					<option value="1" onclick="AddOrDelModel('Checkbox1')"  id="Checkbox1" >入库</option>
					<option value="2" onclick="AddOrDelModel('Checkbox2')"  id="Checkbox2" >出库</option>
					</select>
				</td>
    		</tr>
			<tr>
			    <td class="label"><label for="qty">数量</label></td>
			    <td class="value">
			        <input id="qty" name="qty" value="0" title="Dash Every X Characters" class="validate-digits input-text" type="text"><p class="note" id="note_dash"><span>入库数量</span></p>
			    </td>
    		</tr>
    		<tr>
			    <td class="label"><label for="comment">备注</label></td>
			    <td class="value">
			        <textarea name="comment" class="required-entry" cols="15" rows="2" style="height:100px"></textarea><p class="note" id="note_dash"><span>备注信息</span></p>
			    </td>
    		</tr>
			<tr>
        		<td class="label"></td>
			    <td class="value">
			        <span id="coupons_generate_button"><button id="id_3cf81872242ced1ce5317b5704e032c7" title="保存" type="button" class="scalable generate" onclick="generateCouponCodes('coupons_' ,'<?php echo $this->getUrl('admin_zgb/adminhtml_warehouse/inventoryUpdate');?>', 'warehouseGridJsObject')" style=""><span><span><span>保存</span></span></span></button></span>            </td>
    		</tr>
        </tbody>
    </table>
    </div>
    </div>
</div>
<script type="text/javascript">
	function generateCouponCodes(idPrefix, generateUrl, grid) {
	    $(idPrefix + 'information_fieldset').removeClassName('ignore-validate');
	    var validationResult = $(idPrefix + 'information_fieldset').select('input',
	            'select', 'textarea').collect( function(elm) {
	        return Validation.validate(elm, {
	            useTitle :false,
	            onElementValidate : function() {
	            }
	        });
	    }).all();
	    $(idPrefix + 'information_fieldset').addClassName('ignore-validate');

	    if (!validationResult) {
	        return;
	    }
	    var elements = $(idPrefix + 'information_fieldset').select('input', 'select', 'textarea');

	    elements = elements.concat(
	        $$('#rule_uses_per_coupon'),
	        $$('#rule_uses_per_customer'),
	        $$('#rule_to_date')
	    );

	    var params = Form.serializeElements(elements, true);
	    params.form_key = FORM_KEY;
	    $('messages').update();
	    var couponCodesGrid = eval(grid);
	    new Ajax.Request(generateUrl, {
	        parameters :params,
	        method :'post',
	        onComplete : function (transport, param){
	            var response = false;
	            if (transport && transport.responseText) {
	                response = eval('(' + transport.responseText + ')');
	            }
	            if (couponCodesGrid) {
	            	jQuery.get('<?php echo $this->getUrl("admin_zgb/adminhtml_warehouse/qtyUpdate") ?>?product_id='+jQuery("#product_id").val()+"&store="+jQuery("#store_id").val(),function(qty){
	            		qty = parseInt(qty);
	            		if(qty)
	            		{
	            			jQuery("#original_inventory_qty").val(qty);
	            			jQuery("#inventory_qty").val(qty);
							jQuery("#inventory_stock_availability").val(1);
						}
						else {
							jQuery("#original_inventory_qty").val(0);
							jQuery("#inventory_qty").val(0);
							jQuery("#inventory_stock_availability").val(0);
	            		}
	            		
	            	});
	                couponCodesGrid.reload();
	                
	            }
	            if (response && response.messages) {
	                $('messages').update(response.messages);
	            }
	            if (response && response.error) {
	                alert(response.message);
	            }
	        }
	    });
	}
</script>
<?php echo $this->getLayout()->createBlock('zgb/adminhtml_product_tab_warehouse_grid')->toHtml(); ?>